package javabase.schoolwork.day5_28;

/**
 * @author fance
 * @date 2018/5/29 11:34
 */
public class ReverseArray extends Array {
    public ReverseArray() {
    }

    public ReverseArray(int init_size) {
        super(init_size);
    }
    public void reverse() {
        int cur = foot - 1;
        reverse(elementData,0,cur);
    }
    private void reverse(int[] a,int lo,int hi) {
        while (lo < hi) {
            swap(a,lo,hi);
            lo++;
            hi--;
        }
    }
    private void swap(int[] a,int i, int j) {
        int tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
    }

    public static void main(String[] args) {
        ReverseArray array = new ReverseArray();
        for (int i = 0; i < 20; i++) {
            array.add(i);
        }
        array.reverse();
        System.out.println(array);
    }
}
